<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>15 - The OpenBSD packages and ports system</title>
<link rev= "made" href= "mailto:www@openbsd.org">
<meta name= "resource-type" content= "document">
<meta name= "description"   content= "the OpenBSD FAQ page">
<meta name= "keywords"      content= "openbsd,faq">
<meta name= "distribution"  content= "global">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>

<!--
Copyright (c) 2005-2008 Steven Mestdagh <steven@openbsd.org>

Permission to use, copy, modify, and distribute this documentation for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.

THE DOCUMENTATION IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS DOCUMENTATION INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS DOCUMENTATION
-->

<body bgcolor= "#ffffff" text= "#000000">

<a href="../../zh/index.html">
<img alt="[OpenBSD]" height=30 width=141 src="../../images/smalltitle.gif" border="
0">
</a>
<p>
<font color= "#0000e0">
<a href= "index.html">[FAQ 索引]</a>
<a href= "../faq14.html">[到 14 - 配置磁盘]</a>
</font>

<h1><font color="#e00000">15 - OpenBSD 的软件包和 ports 系统</font></h1><hr>

<h3>目录</h3>
<ul>
<li><a href="#Intro"          >15.1 - 介绍</a>
<li><a href="#PkgMgmt"        >15.2 - 软件包管理</a>
  <ul>
  <li><a href="#PkgHow"       >15.2.1 - 它是如何工作的?</a>
  <li><a href="#Easy"         >15.2.2 - 让工作更方便: PKG_PATH</a>
  <li><a href="#PkgFind"      >15.2.3 - 查找软件包</a>
  <li><a href="#PkgInstall"   >15.2.4 - 安装新软件包</a>
  <li><a href="#PkgList"      >15.2.5 - 列出已经安装的软件包</a>
  <li><a href="#PkgUpdate"    >15.2.6 - 升级已经安装的软件包</a>
  <li><a href="#PkgRemove"    >15.2.7 - 删除已经安装的软件包</a>
<!--  <li><a href="#PkgSecurity"  >15.2.8 - Security updates (-stable packages)</a> -->
  <li><a href="#PkgPartial"   >15.2.8 - 不完全软件包的安装或删除</a>
  </ul>
<li><a href="#Ports"          >15.3 - 使用 ports</a>
  <ul>
  <li><a href="#PortsHow"     >15.3.1 - 它是如何工作的?</a>
  <li><a href="#PortsFetch"   >15.3.2 - 获得 ports</a>
  <li><a href="#PortsConfig"  >15.3.3 - 配置 ports</a>
  <li><a href="#PortsSearch"  >15.3.4 - 搜索 ports</a>
  <li><a href="#PortsInstall" >15.3.5 - 简单的安装: 一个简单的例子</a>
  <li><a href="#PortsClean"   >15.3.6 - 构建后的清理</a>
  <li><a href="#PortsDelete"  >15.3.7 - 删除使用 ports 安装的软件包</a>
  <li><a href="#PortsFlavors" >15.3.8 - 定制选项和子软件包</a>
<!--  <li><a href="#PortsSecurity">15.3.9 - Security updates (-stable)</a> -->
  </ul>
<li><a href="#PkgFAQ"         >15.4 - FAQ</a>
  <ul>
  <li><a href="#NoFun"        >15.4.1 - 我遇到了各种各样的令人沮丧的错误。
我好象根本不能让 ports 工作!</a>
  <li><a href="#Latest"       >15.4.2 - 没有我很喜欢的软件的最新版本!</a>
  <li><a href="#NoPkg"        >15.4.3 - 为什么没有我很喜欢的软件的 package?</a>
  <li><a href="#NoPort"       >15.4.4 - 为什么没有我很喜欢的软件的 ports?</a>
  <li><a href="#NotInBase"    >15.4.5 -
为什么我很喜欢的软件没有包含在基本系统中?</a>
  <li><a href="#PkgVsPorts"   >15.4.6 - 我应该使用什么: package 还是 ports?</a>
  <li><a href="#Knobs"        >15.4.7 - 我该怎么调谐这些 ports
以获得最大性能?</a>
  <li><a href="#Wait"         >15.4.8 - 几周前，我递交了新的或升级的 ports。
为什么它没有被提交?</a>
  </ul>
<li><a href="#Problems"       >15.5 - 报告问题</a>
<li><a href="#Helping"        >15.6 - 帮助我们</a>
</ul>

<a name="Intro"></a>
<h2>15.1 - 介绍</h2>

<p>
There are a lot of third party applications available which one might
want to use on an OpenBSD system.
To make this software easier to install and manage, plus to help it
comply with OpenBSD's policy and goals, the third party software is
<i>ported</i> to OpenBSD.
This porting effort can involve many different things.
Examples are: making the software use the standard OpenBSD directory
layout (e.g. configuration files go into <tt>/etc</tt>), conforming
to OpenBSD's shared library specifications, making the software more
secure whenever possible, etc.

<p>
The end result of the porting effort are ready-to-install binary
packages.
The aim of the package system is to keep track of which software gets
installed, so that it may at any time be updated or removed very easily.
This way, no unnecessary files are left behind, and users can keep their
systems clean.
The package system also helps ensure nothing is deleted by accident,
causing software to stop functioning properly.
Another advantage is that <b>users rarely need to compile software from
source</b>, as packages have already been compiled and are available and
ready to be used on an OpenBSD system.
In minutes, a large number of packages can be fetched and installed,
with everything in the right place.

<p>
<b><font color="#e00000">
The packages and ports collection does NOT go through the same thorough
security audit that is performed on the OpenBSD base system.
Although we strive to keep the quality of the packages collection high,
we just do not have enough human resources to ensure the same level of
robustness and security.
</font></b>
Of course <a href="#PortsSecurity">security updates</a> for various
applications are committed to the ports tree as soon as possible, and
corresponding package security updates are made available as
snapshots for <i>-current</i>.

<a name="PkgMgmt"></a>
<h2>15.2 - 软件包管理</h2>

<a name="PkgHow"></a>
<h3>15.2.1 - 它是如何工作的?</h3>

<p>
Packages are the pre-compiled binaries of some of the most used
third party software.

Packages can be managed easily with the help of several utilities,
also referred to as the pkg* tools:
<ul>
<li><a href="http://www.openbsd.org/cgi-bin/man.cgi?query=pkg_add&amp;sektion=1&amp;manpath=OpenBSD+4.3">pkg_add(1)</a>
  - a utility for installing and upgrading software packages.
<li><a href="http://www.openbsd.org/cgi-bin/man.cgi?query=pkg_delete&amp;sektion=1&amp;manpath=OpenBSD+4.3">pkg_delete(1)</a>
  - a utility for deleting previously installed software packages.
<li><a href="http://www.openbsd.org/cgi-bin/man.cgi?query=pkg_info&amp;sektion=1&amp;manpath=OpenBSD+4.3">pkg_info(1)</a>
  - a utility for displaying information about software packages.
<li><a href="http://www.openbsd.org/cgi-bin/man.cgi?query=pkg_create&amp;sektion=1&amp;manpath=OpenBSD+4.3">pkg_create(1)</a>
  - a utility for creating software packages.
</ul>

<p>
In order to run properly, an application X may require that
other applications Y and Z be installed.
Application X is said to be dependent on these other applications,
which is why Y and Z are called <i>dependencies</i> of X.
In turn, Y may require other applications P and Q, and Z may require
application R to function properly.
This way, a whole <i>dependency tree</i> is formed.

<p>
Packages look like simple <tt>.tgz</tt> bundles.
Basically they are just that, but there is one crucial difference:
they contain some extra <i>packing information</i>.
This information is used by
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=pkg_add&amp;sektion=1&amp;manpath=OpenBSD+4.3">pkg_add(1)</a>
for several purposes:

<ul>
<li>Different checks: has the package already been installed or does it
conflict with other installed packages or file names?
<li>Dependencies which are not yet present on the system, are
automatically fetched and installed, before proceeding with the
installation of the package.
<li>Information about the package(s) is recorded in a central
repository, by default located in <tt>/var/db/pkg/</tt>.
This will, among other things, prevent the dependencies of a package
from being deleted before the package itself has been deleted.
This helps ensure that an application cannot be accidentally broken
by a careless user.
</ul>


<a name="Easy"></a>
<h3>15.2.2 - 让工作更方便: PKG_PATH</h3>

<p>
You can make things really easy by using the <tt>PKG_PATH</tt>
environment variable.
Just point it to your favorite location, and pkg_add(1) will
automatically look there for any package you specify, <b>and</b>
also fetch and install the necessary dependencies of this package
automatically.

<p>
A list of possible locations to fetch packages from is given in the
<a href="#PkgFind">following section</a>.

<p>
Example 1: fetching from your <a href="../../zh/orders.html">CDROM</a>,
assuming you mounted it on <tt>/mnt/cdrom</tt>
<blockquote><pre>
$ <b>export PKG_PATH=/mnt/cdrom/4.3/packages/`machine -a`/</b>
</pre></blockquote>

<p>
Example 2: fetching from a nearby <a href="../../zh/ftp.html">FTP mirror</a>
<blockquote><pre>
$ <b>export PKG_PATH=ftp://your.ftp.mirror/pub/OpenBSD/4.3/packages/`machine -a`/</b>
</pre></blockquote>

<p>
It's usually a good idea to add a line similar to the above examples to
your <tt>~/.profile</tt>.
As with the classic <tt>PATH</tt> variable, you can specify
multiple locations, separated by colons.
<b>Prior to OpenBSD 4.4, every path in the <tt>PKG_PATH</tt> variable MUST
end in a slash (/).</b>
That way, pkg_add(1) can split the path correctly even if it holds URL
schemes containing colons.
If the first entry in <tt>PKG_PATH</tt> fails, the next one will be
tried, and so on, until the package is found.
If all entries fail, an error is produced.

<p>
Notice the use of
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=machine&amp;sektion=1">machine(1)</a>
in the above command lines.
This automatically substitutes your installed OpenBSD "application
architecture", which is usually, but not always, your platform name.
Of course, if you are using snapshots, you will replace "4.3" with
"snapshots".


<a name="PkgFind"></a>
<h3>15.2.3 - 查找软件包</h3>

A large collection of pre-compiled packages is available for the most common
architectures.
Just look for your package in one of these places:

<ul>
<li>On one of the three <a href="../../zh/orders.html">CD-ROMs</a>,
depending on your architecture.
The CD-ROMs carry only the most commonly used, freely distributable
packages for the most commonly used platforms.
<li>On the <a href="../../zh/ftp.html">FTP mirror servers</a>.
Packages are located in the <tt>/pub/OpenBSD/4.3/packages</tt> directory.
From there, packages are broken down depending on architecture.
<li>In the package lists on the OpenBSD website:
<ul>
<li><a href="http://www.openbsd.org/4.3_packages/">Packages for OpenBSD 4.3</a>
<li><a href="http://www.openbsd.org/4.2_packages/">Packages for OpenBSD 4.2</a>
<li><a href="http://www.openbsd.org/4.1_packages/">Packages for OpenBSD 4.1</a>
</ul>
</ul>

<p>
If you have the ports tree on your system, you can quickly find the
package you are looking for as explained in
<a href="#PortsSearch">Searching the ports tree</a>.

<p>
You will notice that certain packages are available in a few different
varieties, formally called <b>flavors</b>.
Others are pieces of the same application which may be installed separately.
They are called <b>subpackages</b>.
This will be detailed further in <a href="#PortsFlavors">Using flavors and
subpackages</a> but flavor basically means they are configured with
different sets of options.
Currently, many packages have flavors, for example: database support,
support for systems without X, or network additions like SSL and IPv6.
Every flavor of a package will have a different suffix in its package
name.
For detailed information about package names, please refer to
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=packages-specs&amp;sektion=7">packages-specs(7)</a>.

<p>
<b>Note:</b>
Not all possible packages are necessarily available on the FTP
servers!
Some applications simply don't work on all architectures.
Some applications can not be distributed via FTP (or CDROM) for licensing
reasons.
There may also be many possible combinations of flavors of a port,
and the OpenBSD project just does not have the resources to build them all.
If you need a combination which is not available, you will have to build
the port from source.
For more information on how to do that, read
<a href="#PortsFlavors">Using flavors and subpackages</a> in the Ports
section of this document.


<a name="PkgInstall"></a>
<h3>15.2.4 - 安装新软件包</h3>

To install packages, the utility
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=pkg_add&amp;sektion=1&amp;manpath=OpenBSD+4.3">pkg_add(1)</a>
is used.
If you have <a href="#Easy">made things easy</a> for yourself by setting
the <tt>PKG_PATH</tt> environment variable, you can just call pkg_add(1)
with the package name, as in the following basic example.

<blockquote><pre>
$ <b>sudo pkg_add -v screen-4.0.3p0</b>
parsing screen-4.0.3p0
installed /etc/screenrc from /usr/local/share/examples/screen/screenrc | 71%
screen-4.0.3p0: complete
</pre></blockquote>

<p>
In this example the <b>-v</b> flag was used to give a more verbose
output.
This option is not needed but it is helpful for debugging and was
used here to give a little more insight into what pkg_add(1) is actually
doing.
Notice the message mentioning <i>/etc/screenrc</i>.
Specifying multiple <b>-v</b> flags will produce even more
verbose output.

<p>
<h4>Using pkg_add(1) in interactive mode</h4>

Since OpenBSD 3.9, pkg_add(1) has an interactive mode, which is enabled
by invoking it with the <b>-i</b> flag, and which causes it to ask you
questions when it cannot make decisions by itself.
For example, if you don't know the version number of a package beforehand,
you can try something like:

<blockquote><pre>
$ <b>sudo pkg_add -i screen</b>
Ambiguous: screen could be screen-4.0.3p0 screen-4.0.3p0-shm screen-4.0.3p0-static
Choose one package
         0: &lt;None&gt;
         1: screen-4.0.3p0
         2: screen-4.0.3p0-shm
         3: screen-4.0.3p0-static
Your choice: 1
screen-4.0.3p0: complete
</pre></blockquote>


<p>
For some packages, some important additional information will be given
about the configuration or use of the application on an OpenBSD system.
Since it is important, it will be displayed whether or not you use the
<b>-v</b> flag.
Consider the following example:

<blockquote><pre>
$ <b>sudo pkg_add ghostscript-fonts-8.11</b>
ghostscript-fonts-8.11: complete
You may wish to update your font path for /usr/local/share/ghostscript/fonts
--- ghostscript-fonts-8.11 -------------------
To install these fonts for X11, just make sure that the fontpath
lists the 75dpi or 100dpi bitmap fonts before the ghostscript fonts,
and make sure you have the string ":unscaled" appended to the bitmap
font's fontpath. This way, the bitmap fonts will be used if they
match, and the Type 1 versions will be used if the font needs to be
scaled. Below is the relevant section from a typical xorg.conf file.

   FontPath   "/usr/X11R6/lib/X11/fonts/misc/"
   FontPath   "/usr/X11R6/lib/X11/fonts/75dpi/:unscaled"
   FontPath   "/usr/X11R6/lib/X11/fonts/100dpi/:unscaled"
   FontPath   "/usr/local/lib/X11/fonts/ghostscript/"
   FontPath   "/usr/X11R6/lib/X11/fonts/Type1/"
</pre></blockquote>

<p>
Let us now continue with an example of a package which has dependencies:

<blockquote><pre>
$ <b>sudo pkg_add -v tin-1.8.2p0</b>
parsing tin-1.8.2p0
Dependencies for tin-1.6.2 resolve to: gettext-0.14.6, libutf8-0.8, pcre-6.4p1, libiconv-1.9.2p3 (todo: libiconv-1.9.2p3,gettext-0.14.6,pcre-6.4p1,libutf8-0.8)
tin-1.8.2p0:parsing libiconv-1.9.2p3
tin-1.8.2p0:libiconv-1.9.2p3: complete
tin-1.8.2p0:parsing gettext-0.14.6
Dependencies for gettext-0.14.6 resolve to: expat-2.0.0, libiconv-1.9.2p3 (todo: expat-2.0.0)
tin-1.8.2p0:parsing expat-2.0.0
tin-1.8.2p0:expat-2.0.0: complete
tin-1.8.2p0:gettext-0.14.6: complete
tin-1.8.2p0:parsing pcre-6.4p1
tin-1.8.2p0:pcre-6.4p1: complete
tin-1.8.2p0:parsing libutf8-0.8
tin-1.8.2p0:libutf8-0.8: complete
tin-1.8.2p0: complete
</pre></blockquote>

Again we added the <b>-v</b> flag to see more of what is happening.
Upon investigating the packing information, dependencies are found and
they are installed first.
Somewhere in the middle you can see the gettext package being installed,
which depends on libiconv.
Before installing gettext, its packing information is examined and it
is verified whether libiconv has already been installed.

<p>
It is possible to specify multiple package names on one line, which
then all get installed at once, along with possible dependencies.

<p>
If for some reason you decide not to use <tt>PKG_PATH</tt>, it is also
possible to specify the absolute location of a package on the command line.
This absolute location may be a local path, or a URL referring to
FTP, HTTP, or SCP locations.
Let's consider installation via FTP in the next example:

<blockquote><pre>
$ <b>sudo pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.3/packages/`machine -a`/screen-4.0.3p0.tgz</b>
screen-4.0.3p0: complete
</pre></blockquote>

<p>
In this example the <b>-v</b> flag wasn't used, so only
needed messages are shown.
Notice that the complete filename was entered by adding a <b>.tgz</b> suffix.
You can also skip this suffix as in the previous examples since it is
auto-completed by pkg_add(1).

<p>
<b>Note:</b> Not all architectures have the same packages available.
Some ports do not work on certain architectures, and performance limits
the number of packages that can be built on others.

<p>
For safety, if you are installing a package which you had installed
earlier (or an older version of it) and removed, pkg_add(1) will
<b>not</b> overwrite configuration files which have been modified.
Instead, it will inform you about this as follows (only when using the
<b>-v</b> flag, however!):

<blockquote><pre>
$ <b>sudo pkg_add -v screen-4.0.3p0</b>
parsing screen-4.0.3p0
The existing file /etc/screenrc has NOT been changed**                 | 71%
It does NOT match the sample file /usr/local/share/examples/screen/screenrc
You may wish to update it manually
screen-4.0.3p0: complete
</pre></blockquote>

Sometimes you may encounter an error like the one in the following
example:

<blockquote><pre>
$ <b>sudo pkg_add xv-3.10ap4</b>
xv-3.10ap4:jpeg-6bp3: complete
xv-3.10ap4:png-1.2.14p0: complete
xv-3.10ap4:tiff-3.8.2p0: complete
Can't install xv-3.10ap4: lib not found X11.9.0
Even by looking in the dependency tree:
        tiff-3.8.2p0, jpeg-6bp3, png-1.2.14p0
Maybe it's in a dependent package, but not tagged with @lib ?
(check with pkg_info -K -L)
If you are still running 3.6 packages, update them.
</pre></blockquote>

There is pkg_add(1) nicely installing dependencies, when all of a sudden
it aborts the installation of xv.
This is another safety precaution which is available since OpenBSD 3.7.
The packing information bundled in the package includes information
about shared libraries that the package expects to be installed,
system libraries as well as third party libraries.
If one of the required libraries cannot be found, the package is not
installed because it would not function anyway.

<p>
To solve this type of conflict, you must find out what to install
in order to get the required libraries on your system.

<!--
insert a good algorithm here
-->

There are several things to check:
<ul>
<li>You may have older packages installed: an older version of the
required library is present.
In this case, upgrade these packages.
<li>Your system may be incomplete: you did not install one of the
file sets, which contains the required library.
Just <a href="faq4.html#AddFileSet">add the required file set.</a>
<li>Your system may be out of date: you have an older version of the
required library.
Boot the installer (as detailed in <a href="faq4.html">FAQ 4</a>),
and choose to (U)pgrade your complete system.
</ul>

<a name="PkgList"></a>
<h3>15.2.5 - 列出已经安装的软件包</h3>

You can see a list of installed packages by using the
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=pkg_info&amp;sektion=1&amp;manpath=OpenBSD+4.3">pkg_info(1)</a>
utility.

<blockquote><pre>
$ <b>pkg_info</b>
aterm-0.4.2p1       color vt102 terminal emulator with transparency support
bzip2-1.0.4         block-sorting file compressor, unencumbered
expat-2.0.0         XML 1.0 parser written in C
fluxbox-0.9.15.1p0  window manager based on the original Blackbox code
gettext-0.14.6      GNU gettext
imlib2-1.3.0        image manipulation library
jpeg-6bp3           IJG's JPEG compression utilities
libiconv-1.9.2p3    character set conversion library
libltdl-1.5.22p1    GNU libtool system independent dlopen wrapper
libungif-4.1.4p0    tools and library routines for working with GIF images
libutf8-0.8         provides UTF-8 locale support
mutt-1.4.2.2i       tty-based e-mail client
pcre-6.4p1          perl-compatible regular expression library
png-1.2.14p0        library for manipulating PNG images
screen-4.0.3p0      multi-screen window manager
tcsh-6.14.00p1      extended C-shell with many useful features
tiff-3.8.2p0        tools and library routines for working with TIFF images
tin-1.8.2p0         threaded NNTP and spool based UseNet newsreader
</pre></blockquote>

<p>
When given an installed package name (or a location of a package which is to
be installed), pkg_info(1) will show more detailed information about that
specific package.

<a name="PkgUpdate"></a>
<h3>15.2.6 - 升级已经安装的软件包</h3>

Since OpenBSD 3.7, it is possible to update existing packages by using
the <b>-r</b> (= replace) switch to
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=pkg_add&amp;sektion=1&amp;manpath=OpenBSD+4.3">pkg_add(1)</a>.
OpenBSD 3.8 introduced the <b>-u</b> switch to pkg_add(1), which has been
turned into a true update mechanism in 3.9.

<p>
Let's say you had an older version of unzip installed before upgrading this
box from OpenBSD 4.2 to 4.3.
Now you can easily upgrade to the newer 4.3 package as follows:

<blockquote><pre>
$ <b>sudo pkg_add -u unzip</b>
unzip-5.52 (extracting): complete
unzip-5.51 (deleting): complete
unzip-5.52 (installing): complete
Clean shared items: complete
</pre></blockquote>

<p>
When a package has dependencies, they are also examined for updates.
Invoking pkg_add(1) with the <b>-u</b> flag and no package name will
try to update all installed packages.

<p>
<b>Note:</b>
The <b>-u</b> switch relies on the <tt>PKG_PATH</tt> environment variable.
If it is not set, pkg_add(1) will not be able to find updates.

<p>
Starting with OpenBSD 4.2, having several entries in <tt>PKG_PATH</tt> does
no longer mean all entries will be tried for update operations.
Instead, pkg_add(1) will stop at the first path with matching candidates.

<p>
If you had a configuration file belonging to the old version, which
you modified, it will be left untouched by default.
You can, however, replace it with the default configuration file of
the new version, by calling pkg_add(1) with the <b>-c</b> flag.

<a name="PkgRemove"></a>
<h3>15.2.7 - 删除已经安装的软件包</h3>

<p>
To delete a package, simply take the proper name of the package as shown
by pkg_info(1) (see <a href="#PkgList">Listing installed packages</a>
above) and use
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=pkg_delete&amp;sektion=1&amp;manpath=OpenBSD+4.3">pkg_delete(1)</a>
to remove the package.
In the example below, the screen package is being removed.
Notice that on some occasions there are instructions of extra items
that need to be removed that pkg_delete(1) did not remove for you.
As with the pkg_add(1) utility, you can use the <b>-v</b> flag to
get more verbose output.

<blockquote><pre>
$ <b>sudo pkg_delete screen</b>
screen-4.0.3p0: complete
Clean shared items: complete
</pre></blockquote>

<p>
<b>Note:</b> Often, it is not necessary to specify the version numbers
and flavors with the package name, since pkg_delete(1) will usually be
able to find the full name by itself.
You need to specify the complete package name (in the example, that is
screen-4.0.3p0) only if ambiguity is possible due to multiple installed
packages with the specified name. In that case pkg_delete(1) cannot
know which package to delete.

<p>
For safety, pkg_delete(1) will not remove configuration files if they
have been modified.
Instead it will inform you about this as follows:

<blockquote><pre>
$ <b>sudo pkg_delete screen</b>
screen-4.0.3p0: complete
Clean shared items: complete
--- screen-4.0.3p0 -------------------
You should also remove /etc/screenrc (which was modified)
</pre></blockquote>

<p>
If you prefer to have those configuration files removed automatically,
you can do so by using the <b>-c</b> flag.


<!--
<a name="PkgSecurity"></a>
<h3>15.2.8 - Security updates (-stable packages)</h3>

When serious bugs or security flaws are discovered in third party
software, they are fixed in the -stable branch of the ports tree,
and a selection of updated binary packages is made available.

<p>
Please refer to the
<a href="../pkg-stable.html">stable packages page</a> to find out about
updated packages and important updates to the -stable branch.
Note that updated packages are only available for the i386 and amd64 platforms.
For other platforms, you will need to use the -stable branch of the ports
tree and compile from source.

<p>
If you want to receive security announcements related to software in
the packages and ports system, you can subscribe to the ports-security
<a href="../mail.html">mailing list</a>.

<p>
Package names are <b>always</b> changed in case of a package update,
to avoid any risk of confusion between a package from the release
and a bug-fixed package.
This name change may be a higher version number or, in case the version
number remains the same, a <b>pN</b> suffix is added, where <b>N+1</b>
represents the number of times this package has been patched.
-->

<a name="PkgPartial"></a>
<h3>15.2.8 - 不完全软件包的安装或删除</h3>

In some odd cases, you may find that a package was not added or deleted
completely, because of conflicts with other files.
The incomplete installation is usually marked with "partial-" prepended
to the package name.
This can, for instance, happen when you coincidentally press CTRL+C
during installation:

<blockquote><pre>
$ <b>sudo pkg_add screen-4.0.3p0</b>
screen-4.0.3p0: complete                                                      7%
Adjusting md5 for /usr/local/info/screen.info-3 from 49fb3fe1cc3a3b0057518459811b6dac to 3b9c7811244fb9f8d83bb27d3a0f60d8
/usr/sbin/pkg_add: Installation of screen-4.0.3p0 failed , partial installation recorded as partial-screen-4.0.3p0
</pre></blockquote>

<p>
It is always a good idea to remove partial packages from your
system, and to fix potential problems that lead to this failure.
It is often an indication that you do not have a clean system with
everything installed from packages, but possibly packages mixed up with
other software installed straight from source.


<a name="Ports"></a>
<h2>15.3 - 使用 ports</h2>

As mentioned in the introduction, packages are compiled from the ports
tree.
In this section we will explain how the ports tree works, when you should
use it and how you can use it.

<p>
<b>IMPORTANT NOTE</b>: The ports tree is meant for advanced users.
<b>Everyone is encouraged to use the pre-compiled binary
<a href="#PkgMgmt">packages</a></b>.
Do NOT ask beginner questions on the mailing lists like
"How can I get the ports tree working?".
If you have questions about the ports tree, it is assumed that you have
read the manual pages and this FAQ, and that you are able to work with it.


<a name="PortsHow"></a>
<h3>15.3.1 - 它是如何工作的?</h3>

The ports tree, a concept originally borrowed from
<a href="http://www.freebsd.org">FreeBSD</a>, is a set of Makefiles,
one for each third party application, for controlling

<ul>
<li>where and how to fetch the source of the software,
<li>which other software it depends upon,
<li>how to alter the sources (if necessary),
<li>how to configure and build it,
<li>how to test it (optional),
<li>how to install it.
</ul>

<p>
Apart from the Makefile, each port also contains at least the following:

<ul>
<li>a PLIST or packing list, which contains instructions for package
creation once the application has been built,
<li>a DESCR or description of the application,
<li>a distfile, containing distribution file checksums and size.
</ul>

<p>
All this information is kept in a directory hierarchy under
<tt>/usr/ports</tt>.
This hierarchy contains three special subdirectories:
<ul>
<li><tt>distfiles/</tt> - where the ports system stores
software distribution sets after downloading.
<li><tt>infrastructure/</tt> - the main directory of the ports
infrastructure, containing all necessary scripts and makefiles.
<li><tt>packages/</tt> - contains all binary packages built by the ports
system.
</ul>
The other subdirectories all form different application categories,
which contain the subdirectories of the actual ports.
Complex ports may be organized to an even deeper level, for example if
they have a core part and a set of extensions, or a stable and a snapshot
version of the application.
Every port directory must contain a <tt>pkg/</tt> subdirectory containing
packing list(s) and description file(s).
There may also be <tt>patches/</tt> and <tt>files/</tt> subdirectories,
for source patches and additional files, respectively.

<p>
When a user issues
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=make&amp;sektion=1">make(1)</a>
in the subdirectory of a specific port, the system will recursively
walk its dependency tree, check whether the required dependencies are
installed, build and install any missing dependencies, and then
continue the build of the desired port.
All of the building happens inside the <i>working directory</i> that
the port creates.
This is either a subdirectory of the port's main directory, in which case
it is recognized by its prefix "w-", or a subdirectory of <tt>${WRKOBJDIR}</tt>,
if the <tt>WRKOBJDIR</tt> variable has been set (see
<a href="#PortsConfig">Configuration of the ports system</a>).

<p>
<b>Note:</b> Ports are never directly installed on your system!
They use a <i>fake installation directory</i>.
Everything that gets installed there, is bundled together into a
package (which is stored in the <tt>packages/</tt> subdirectory of the
ports tree as mentioned earlier).
Installing a port really means: creating a package, and then
installing that package!

<p>
<b>More information</b> about the ports system may be found in these
manual pages:

<ul>
<li><a href="http://www.openbsd.org/cgi-bin/man.cgi?query=ports&amp;sektion=7">ports(7)</a>
- describes the different stages (make targets) of port installation,
the use of flavors and subpackages and some other options.
<li><a href="http://www.openbsd.org/cgi-bin/man.cgi?query=bsd.port.mk&amp;sektion=5">bsd.port.mk(5)</a>
- in depth information about all the make targets, variables, the fake
(installation directory) framework, etc.
</ul>

<a name="PortsFetch"></a>
<h3>15.3.2 - 获得 ports</h3>

Before continuing, you must read the section about NOT
<a href="#NoFun">mixing up your OpenBSD system and ports tree</a>.
Once you have decided which flavor of the ports tree you want, you can
get the ports tree from different sources.
The table below gives an overview of where you can find the different
flavors, and in which form.
An 'x' marks availability and '-' means it is not available through
that specific source.

<p>
<table border="1" align="center" style="empty-cells: show;">
<tr align="center">
<td align="left">Source</td>
<td>Form</td>
<td colspan="4">Flavor</td>
</tr>
<tr align="center">
<td colspan="2"></td>
<td>-release</td>
<td>-stable</td>
<td>snapshots</td>
<td>-current</td>
</tr>
<tr align="center">
<td align="left"><a href="../../zh/orders.html">CD-ROM</a></td>
<td>.tar.gz</td>
<td>x</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr align="center">
<td align="left"><a href="../../zh/ftp.html">FTP mirrors</a></td>
<td>.tar.gz</td>
<td>x</td>
<td>-</td>
<td>x</td>
<td>-</td>
</tr>
<tr align="center">
<td align="left"><a href="../../zh/anoncvs.html">AnonCVS</a></td>
<td>cvs checkout</td>
<td>x</td>
<td>x</td>
<td>-</td>
<td>x</td>
</tr>
</table>

<p>
On the CD-ROM and FTP mirrors, look for a file named <tt>ports.tar.gz</tt>.
You want to untar this file in the <tt>/usr</tt> directory, which will
create <tt>/usr/ports</tt>, and all the directories under it.
For example:

<blockquote><pre>
$ <b>cd /tmp</b>
$ <b>ftp ftp://ftp.openbsd.org/pub/OpenBSD/4.3/ports.tar.gz</b>
$ <b>cd /usr</b>
$ <b>sudo tar xzf /tmp/ports.tar.gz</b>
</pre></blockquote>

<p>
The snapshots available on the FTP mirrors are generated daily from
the -current ports tree.
You will find the snapshots in the <tt>pub/OpenBSD/snapshots/</tt>
directory.
If you are using a snapshot of the ports tree, you should have
installed a matching snapshot of OpenBSD.
Make sure you keep your ports tree and your OpenBSD system in sync!

<p>
For more information about obtaining the ports tree via AnonCVS,
please read the <a href="../../zh/anoncvs.html">AnonCVS page</a> which
contains a list of available servers and a number of examples.


<a name="PortsConfig"></a>
<h3>15.3.3 - 配置 ports</h3>

<p>
<b>NOTE:</b>
This section introduces some additional global settings for building
applications from ports.
You can skip this section, but then you will be required to perform many
of the make(1) statements in the examples as root.

<p>
Because the OpenBSD project does not have the resources to fully review
the source code of all software in the ports tree, you can configure the
ports system to take a few safety precautions.
The ports infrastructure is able to perform all building as a regular user,
and perform only those steps that require superuser privileges as root.
Examples are the <tt>fake</tt> and <tt>install</tt> make targets.
However, because root privileges are always required at some point,
the ports system will not save you when you decide to build a malicious
application.

<p>
<ul>
<li>You can set up
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=sudo&amp;sektion=8">sudo(8)</a>
and have the ports system use it for tasks requiring superuser permissions.
Just add a line to <tt>/etc/mk.conf</tt> containing

<blockquote><pre>
SUDO=/usr/bin/sudo
</pre></blockquote>

<li>You can modify the ownerships of the ports tree so that you can write
there as a regular user.
In this case, the regular user has been added to the wsrc group, and the
underlying directories are made group writable.

<blockquote><pre>
# <b>chgrp -R wsrc /usr/ports</b>
# <b>find /usr/ports -type d -exec chmod g+w {} \;</b>
</pre></blockquote>

<li>You can have the ports system use
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=systrace&amp;sektion=1">systrace(1)</a>
by adding the following to <tt>/etc/mk.conf</tt>

<blockquote><pre>
USE_SYSTRACE=Yes
</pre></blockquote>

This enforces the build procedure to stay inside allowed directories, and
prohibits writing in illegal places, thereby considerably reducing the risk
of a damaged system.
Note that the use of systrace(1) adds about 20% overhead in build time.

</ul>

<p>
It is possible to use a read-only ports tree by separating directories
that are written to during port building:

<ul>
<li>The working directory of ports.
This is controlled by the <tt>WRKOBJDIR</tt> variable, which specifies
the directory which will contain the working directories.
<li>The directory containing distribution files.
This is controlled by the <tt>DISTDIR</tt> variable.
<li>The directory containing newly built binary packages.
This is controlled by the <tt>PACKAGE_REPOSITORY</tt> variable.
</ul>

For example, you could add the following lines to <tt>/etc/mk.conf</tt>

<blockquote><pre>
WRKOBJDIR=/usr/obj/ports
DISTDIR=/usr/distfiles
PACKAGE_REPOSITORY=/usr/packages
</pre></blockquote>

If desired, you can also change the ownership of these directories to your
local username and group, so that the ports system can create underlying
working directories as a regular user.


<a name="PortsSearch"></a>
<h3>15.3.4 - 搜索 ports</h3>

Once you have the ports tree in place on your system, it becomes very
easy to search for software.
Just use <tt>make search key="searchkey"</tt>, as shown in the
following example.

<blockquote><pre>
$ <b>cd /usr/ports</b>
$ <b>make search key=rsnapshot</b>
Port:   rsnapshot-1.2.9
Path:   net/rsnapshot
Info:   remote filesystem snapshot utility
Maint:  Sigfred Haversen
Index:  net
L-deps:
B-deps: :net/rsync
R-deps: :net/rsync
Archs:  any
</pre></blockquote>

The search result gives a nice overview of each application that is
found: the port name, the path to the port, a one-line description, the
port's maintainer, keywords related to the port, library/build/runtime
dependencies, and architectures on which the port is known to work.

<p>
This mechanism, however, is a very basic one, which just runs awk(1)
on the ports index file.
Since OpenBSD 4.0, a new port called "sqlports" has been created,
allowing very fine-grained searching using SQL.
It is a SQLite database, but basically just about any database format can be
created using the ports infrastructure.
The sqlports port includes the script used to generate the database, which
could be used as a basis to generate databases in different formats.

<p>
Just pkg_add(1) the sqlports package, and in this case, the sqlite3 package
to get started.
A sample session could look like:

<blockquote><pre>
$ sqlite3 /usr/local/share/sqlports
SQLite version 3.3.12
Enter ".help" for instructions
sqlite> SELECT FULLPKGNAME,COMMENT FROM Ports WHERE COMMENT LIKE '%statistics%';
Guppi-0.40.3p1|GNOME-based plot program with statistics capabilities
mailgraph-1.12|a RRDtool frontend for Postfix statistics
R-2.4.1|clone of S, a powerful math/statistics/graphics language
py-probstat-0.912p0|probability and statistics utilities for Python
darkstat-3.0.540p1|network statistics gatherer with graphs
pfstat-2.2p0|packet filter statistics visualization
tcpstat-1.4|report network interface statistics
wmwave-0.4p2|Window Maker dockapp to display wavelan statistics
diffstat-1.43p0|accumulates and displays statistics from a diff file
sqlite>
</pre></blockquote>

The above is still a very basic search.
With SQL, just about anything can be searched for, including dependencies,
configure flags, shared libraries, etc.

<a name="PortsInstall"></a>
<h3>15.3.5 - 简单的安装: 一个简单的例子</h3>

For clarity's sake, let's consider a simple example: rsnapshot.
This application has one dependency: rsync.

<blockquote><pre>
$ <b>cd /usr/ports/net/rsnapshot</b>
$ <b>make install</b>
===>  Checking files for rsnapshot-1.2.9
&gt;&gt; rsnapshot-1.2.9.tar.gz doesn't seem to exist on this system.
&gt;&gt; Fetch http://www.rsnapshot.org/downloads/rsnapshot-1.2.9.tar.gz.
100% |**************************************************|   173 KB    00:02
&gt;&gt; Size matches for /usr/ports/distfiles/rsnapshot-1.2.9.tar.gz
&gt;&gt; Checksum OK for rsnapshot-1.2.9.tar.gz. (sha1)
===&gt;  rsnapshot-1.2.9 depends on: rsync-2.6.9 - not found
===&gt;  Verifying install for rsync-2.6.9 in net/rsync
===&gt;  Checking files for rsync-2.6.9
&gt;&gt; rsync-2.6.9.tar.gz doesn't seem to exist on this system.
&gt;&gt; Fetch ftp://ftp.samba.org/pub/rsync/old-versions/rsync-2.6.9.tar.gz.
100% |**************************************************|   792 KB    00:31
&gt;&gt; Size matches for /usr/ports/distfiles/rsync-2.6.9.tar.gz
&gt;&gt; Checksum OK for rsync-2.6.9.tar.gz. (sha1)
===&gt;  Verifying specs:  c
===&gt;  found c.40.3
===&gt;  Extracting for rsync-2.6.9
===&gt;  Patching for rsync-2.6.9
===&gt;  Configuring for rsync-2.6.9
  [...snip...]
===&gt;  Building for rsync-2.6.9
  [...snip...]
===&gt;  Faking installation for rsync-2.6.9
  [...snip...]
===&gt;  Building package for rsync-2.6.9
Link to /usr/ports/packages/i386/ftp/rsync-2.6.9.tgz
Link to /usr/ports/packages/i386/cdrom/rsync-2.6.9.tgz
===&gt;  Installing rsync-2.6.9 from /usr/ports/packages/i386/all/rsync-2.6.9.tgz
rsync-2.6.9: complete
===&gt; Returning to build of rsnapshot-1.2.9
===&gt;  rsnapshot-1.2.9 depends on: rsync-2.6.9 - found
===&gt;  Extracting for rsnapshot-1.2.9
===&gt;  Patching for rsnapshot-1.2.9
===&gt;  Configuring for rsnapshot-1.2.9
  [...snip...]
===>  Building for rsnapshot-1.2.9
  [...snip...]
===&gt;  Faking installation for rsnapshot-1.2.9
  [...snip...]
===&gt;  Building package for rsnapshot-1.2.9
Link to /usr/ports/packages/i386/ftp/rsnapshot-1.2.9.tgz
Link to /usr/ports/packages/i386/cdrom/rsnapshot-1.2.9.tgz
===&gt;  rsnapshot-1.2.9 depends on: rsync-2.6.9 - found
===&gt;  Installing rsnapshot-1.2.9 from /usr/ports/packages/i386/all/rsnapshot-1.2.9.tgz
rsnapshot-1.2.9: complete
</pre></blockquote>

<p>
As you can see, the ports system is doing many things automatically.
It will fetch, extract, and patch the source code, configure and build
(compile) the source, install the files into a fake directory, create
a package (corresponding to the packing list) and install this package
onto your system (usually under <tt>/usr/local/</tt>).
And it does this recursively <b>for all dependencies</b> of the port.
Just notice the
"<tt>===&gt; Verifying install for ...</tt>" and
"<tt>===&gt; Returning to build of ...</tt>" lines in the above output,
indicating the walk through the dependency tree.

<p>
If a previous version of the application you want to install, was
already installed on your system, you can use <tt><b>make
update</b></tt> instead of <tt><b>make install</b></tt>.
This will call pkg_add(1) with the <b>-r</b> flag.

<p>
<b>Note:</b>
Large applications will require a lot of system resources to build.
Good examples are compilers like GCC 4.0 or the Java 2 Software
Development Kit.
If you get "out of memory" type of errors when building such a port,
this usually has one of two causes:

<ul>
<li>Your resource limits are too restrictive.
Adjust them with ksh's ulimit or csh's limit command.
If that doesn't help, just become root before starting the build, or use
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=sudo&amp;sektion=8">sudo(8)</a>
with the <tt>-c</tt> flag to run the build with the resources limited
by the specified login class (refer to
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=login.conf&amp;sektion=5">login.conf(5)</a>
for details about login classes).
<li>You simply don't have enough RAM in your machine.
</ul>


<a name="PortsClean"></a>
<h3>15.3.6 - 构建后的清理</h3>

You probably want to clean the port's default working directory after
you have built the package and installed it.

<blockquote><pre>
$ <b>make clean</b>
===&gt;  Cleaning for rsnapshot-1.2.9
</pre></blockquote>

In addition, you can also clean the working directories of all
dependencies of the port with this make target:

<blockquote><pre>
$ <b>make clean=depends</b>
===&gt;  Cleaning for rsync-2.6.9
===&gt;  Cleaning for rsnapshot-1.2.9
</pre></blockquote>

If you wish to remove the source distribution set(s) of the port, you
would use

<blockquote><pre>
$ <b>make clean=dist</b>
===&gt;  Cleaning for rsnapshot-1.2.9
===&gt;  Dist cleaning for rsnapshot-1.2.9
</pre></blockquote>

In case you have been compiling multiple flavors of the same port,
you can clear the working directories of all these flavors at once using

<blockquote><pre>
$ <b>make clean=flavors</b>
</pre></blockquote>

You can also clean things up as they get built, by setting a special variable.
Work directories will automatically be cleaned after packages have been
created:
<blockquote><pre>
$ <b>make package BULK=Yes</b>
</pre></blockquote>

<a name="PortsDelete"></a>
<h3>15.3.7 - 删除使用 ports 安装的软件包</h3>

It is very easy to uninstall a port:

<blockquote><pre>
$ <b>make uninstall</b>
===&gt; Deinstalling for rsnapshot-1.2.9
rsnapshot-1.2.9: complete
Clean shared items: complete
</pre></blockquote>

This will call pkg_delete(1) to have the corresponding package removed
from your system.
If desired, you can also uninstall and re-install a port's package by
using

<blockquote><pre>
$ <b>make reinstall</b>
===&gt;  Cleaning for rsnapshot-1.2.9
/usr/sbin/pkg_delete rsnapshot-1.2.9
rsnapshot-1.2.9: complete
Clean shared items: complete
===&gt;  Installing rsnapshot-1.2.9 from /usr/ports/packages/i386/all/rsnapshot-1.2.9.tgz
rsnapshot-1.2.9: complete
</pre></blockquote>

If you would like to get rid of the packages you just built, you can do so
as follows:

<blockquote><pre>
$ <b>make clean=packages</b>
===&gt;  Cleaning for rsnapshot-1.2.9
rm -f /usr/ports/packages/i386/all/rsnapshot-1.2.9.tgz
</pre></blockquote>

<a name="PortsFlavors"></a>
<h3>15.3.8 - 定制选项和子软件包</h3>

Please do read the
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=ports&amp;sektion=7">ports(7)</a>
manual page, which gives a good overview of this topic.
There are two mechanisms to control the packaging of software according
to different needs.

<p>
The first mechanism is called <b>flavors</b>.
A flavor usually indicates a certain set of compilation options.
For instance, some applications have a "no_x11" flavor which can be used on
systems without X.
Some shells have a "static" flavor, which will build a statically linked
version.
There are ports which have different flavors for building them with
different graphical toolkits.
Other examples include: support for different database formats,
different networking options (SSL, IPv6, ...), different paper sizes, etc.

<p>
<b>Summary:</b>
Most likely you will use flavors when a package has not been made
available for the flavor you are looking for.
In this case you will specify the desired flavor and build the port
yourself.

<p>
Most port flavors have their own working directory during building
and every flavor will be packaged into a correspondingly named package to
avoid any confusion.
To see the different flavors of a certain port, you would change to its
subdirectory and issue

<blockquote><pre>
$ <b>make show=FLAVORS</b>
</pre></blockquote>

You should also look at the port's DESCR files, as they're supposed to
explain the available flavors.

<p>
The second mechanism is called <b>subpackages</b>.
A porter may decide to create subpackages for different pieces of the
same application, if they can be logically separated.
You will often see subpackages for the client part and the server part
of a program.
Sometimes extensive documentation is bundled in a separate subpackage
because it takes up quite some disk space.
Extra functionality that pulls in heavy dependencies will often be
packaged separately.
The porter will also decide which subpackage is the main subpackage,
to be installed as a default.
Other examples are: extensive test suites which come with the software,
separate modules with support for different things, etc.

<p>
<b>Summary:</b>
Some ports are split into several packages. <tt>make install</tt> will only
install the main subpackage.

<p>
To list the different packages built by a port, use
<blockquote><pre>
$ <b>make show=PACKAGES</b>
</pre></blockquote>
<p>

<tt>make install</tt> will only install the main subpackage.
To install them all, use

<blockquote><pre>
$ <b>make install-all</b>
</pre></blockquote>
<p>

To list the different subpackages available for a port, use

<blockquote><pre>
$ <b>make show=MULTI_PACKAGES</b>
</pre></blockquote>

It is possible to select which subpackage(s) to install from within the
ports tree.
After some tests, this procedure will just call
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=pkg_add&amp;sektion=1&amp;manpath=OpenBSD+4.3">pkg_add(1)</a>
to install the desired subpackage(s).

<blockquote><pre>
$ <b>env SUBPACKAGE="-server" make install</b>
</pre></blockquote>

<p>
<b>Note:</b>
The subpackages mechanism only handles packages, it does not modify any
configuration options before building the port.
For that purpose you must use flavors.

<!--
<a name="PortsSecurity"></a>
<h3>15.3.9 - Security updates</h3>

When serious bugs or security flaws are discovered in third party
software, they are fixed in the <b>-stable</b> branch of the ports tree.
Remember that the lifecycle is 1 year: only the current and last release
are updated, as explained in
<a href="faq5.html#Flavors">FAQ 5 - OpenBSD's Flavors</a>.

<p>
This means all you need to do is make sure you check out the correct
branch of the ports tree, and build the desired software from it.
You can keep your tree up-to-date with CVS, and in addition subscribe
to the ports-security <a href="../mail.html">mailing list</a> to receive
security announcements related to software in the ports tree.

<p>
Of course, security updates reach the -current ports tree before being
taken up in the -stable branch.
-->

<a name="PkgFAQ"></a>
<h2>15.4 - FAQ</h2>

<a name="NoFun"></a>
<h3>15.4.1 - 我遇到了各种各样的令人沮丧的错误。
我好象根本不能让 ports 工作!</h3>

<p>
It is very likely that you are using a system and ports tree which are
not in sync.

<p>
<i>Sorry?</i>
<ul>
<li>Read EVERYTHING about
<a href="../faq5.html#Flavors">OpenBSD's Flavors</a>:
-release, -stable, and -current.
The short summary is as follows, but please do read the document
mentioned above to get an idea about which one it is you want to use.
<ul>
<li><a href="../../zh/orders.html">Release</a>: What is on the CD.
<li><a href="../../stable.html">Stable</a>: Release, plus security and
  reliability enhancements.
<li><a href="current.html">Current</a>: The development version
  of OpenBSD.
</ul>
<li>Do NOT check out a -current ports tree and expect it to work on
a -release or -stable system.
This is one of the most common errors and you will irritate people when
you ask for help about why "nothing seems to work!"
<b>If you follow -current, you need both a -current system
and a -current ports tree</b>.
Yes, this really does mean a wonderful new port will typically not
work on your "older" system -- even if that system was -current just a
few weeks ago.
Keep in mind that if you use X11 as part of your system, it must also
follow the corresponding branch!
<li>Because no intrusive changes are made in -stable, it is possible to
use -release packages and ports on a -stable system.
There is no need to update all your installed packages after applying
a few errata patches to your system.
</ul>

<p>
Another common failure is a missing X11 installation.
Even if the port you try to build has no direct dependency on X11, a
subpackage of it or its dependencies may require X11 headers and libraries.
Building ports on systems without X11 is not supported, so if you insist
on doing so, you are on your own to figure it out.
For many ports, there are, however, "no_x11" flavored packages available,
which you can install without needing X11 on your system.

<p>
In OpenBSD 4.2, many packages that use libexpat <i>require</i>
xbase42.tgz to be installed, even if they have no graphical functionality.
This is fixed as of OpenBSD 4.3, where libexpat is included in the
base43.tgz file set.
Thus, libexpat no longer depends on any X file sets.
Read the additional notes about this transition in the
<a href="upgrade43.html#libexpat">Upgrade Guide</a>.

<a name="Latest"></a>
<h3>15.4.2 - 没有我很喜欢的软件的最新版本!</h3>

If you are using a release or stable version of OpenBSD, you will not
find any package updates until the next release, or until security
issues occur which justify an update of the port in the -stable branch,
and of the corresponding package.

<p>
<b>WARNING: DO NOT mix versions of Ports and OpenBSD!</b>

<p>
Doing so will sooner or later (probably very soon, in fact) cause you
headaches trying to solve <a href="#NoFun">all kinds of errors</a>!

<p>
<i>But hey, I am all -current here!</i>

<p>
The ports collection is a volunteer project.
Sometimes the project simply doesn't have the developer resources to
keep everything up-to-date.
Developers pretty much pick up what they consider interesting and can
test in their environment.
Your <a href="../../donations.html">donations</a> can make a difference
for testing ports on more platforms.

<p>
Some individual ports may lag behind the mainstream versions because
of this.
The ports collection may have a version back of a program from January
while a new version of the program has been released by its developers
in May three months ago.
Often this is a conscious decision; the new version may have problems
in it on OpenBSD that the maintainer is trying to solve, or that have
simply made the application worse than the old version: OpenBSD may
have different <a href="../../zh/goals.html">goals</a> than the mainstream
developers in other projects, which sometimes results in features and
design or implementation choices that are undesirable from OpenBSD
developers' point of view.
The update may also be postponed because the new version is not
considered a crucial update.

<p>
If you really need a new version of a port, you should ask the
maintainer of the port to update the port
(see <a href="#Problems">below</a> on how to find out who
the maintainer is).
If you can <a href="#Helping">help</a> with this, all the better.


<a name="NoPkg"></a>
<h3>15.4.3 - 为什么没有我很喜欢的软件的 package?</h3>

There are several possible reasons for this:

<ul>
<li>On the OpenBSD <a href="../../zh/orders.html">CD-ROMs</a>, there is no space
to include every possible package for every possible platform.
Therefore only the most used packages are included on the CDs.
Additionally, some software can only be redistributed for free, this
means it cannot be included on the CDs.
If you cannot find a package on the CDs, try another source, such as
an FTP mirror.
<li>Some software must simply not be redistributed in binary package
form at all, according to its license.
Other software is encumbered by patents and can therefore not be
redistributed.
If your Top-Favorite-Software falls into this category, you will need
to use the port and compile from source.
<li>Obvious, but sometimes forgotten: there is
<a href="#NoPort">no port of your Top-Favorite-Software</a>.
You can verify this by <a href="#PortsSearch">searching the ports tree</a>.
If there is indeed no port of your Top-Favorite-Software, then you
are welcome to <a href="#Helping">help</a>.
</ul>

<a name="NoPort"></a>
<h3>15.4.4 - 为什么没有我很喜欢的软件的 ports?</h3>

The ports collection is a volunteer project.
Active port development is done by a limited number of people, in their
spare time.
These people usually make new ports only for software they use directly
or are interested in.

<p>
You can <a href="#Helping">help</a>.
Consider creating your own port.
There is some documentation available on this:
<a href="../../porting.html">Building an OpenBSD Port</a>.
Read it, and read it again.
Especially the part about <i>maintaining</i> your port.
Then try making a new port, and test it carefully and step by step.
If finally it works OK for you, submit it to the ports mailing list
at <a href="mailto:ports@openbsd.org">ports@openbsd.org</a>.
Chances are good you will get some feedback and testing from other
people.
If the testing is successful, your port will be considered to be taken
up in the ports tree.


<a name="NotInBase"></a>
<h3>15.4.5 - 为什么我很喜欢的软件没有包含在基本系统中?</h3>

Because OpenBSD is supposed to be a small stand-alone UNIX-like
operating system, we need to draw a line as to what to include.
Generally, for an application to be included in the base system:

<ul>
<li>It must meet the high quality standards, laid out in the
<a href="../../zh/goals.html">goals</a> of the OpenBSD project.
<li>Its license must not be too restrictive and must be compatible
with the BSD license.
<li>It must not be too large, in order to keep the size of the base
system acceptable.
</ul>

<p>
Further answers to this question are also found in
<a href="../faq1.html#HowAbout">FAQ 1</a>.

<a name="PkgVsPorts"></a>
<h3>15.4.6 - 我应该使用什么: package 还是 ports?</h3>

In general, you are <b>highly advised</b> to use packages
over building an application from ports.
The OpenBSD ports team considers packages to be the goal of their
porting work, not the ports themselves.

<p>
Building a complex application from source is not trivial.
Not only must the application be compiled, but the tools used to
build it must be built as well.
Unfortunately, OpenBSD, the tools, and the application are all evolving,
and often, getting all the pieces working together is a challenge.
Once everything works, a revision in any of the pieces the next day
could render it broken.
Every <a href="../faq1.html#Next">six months</a>, as a
<a href="../faq5.html#Flavors">new release</a> of OpenBSD is made,
an effort is made to test the building of every port on every platform,
but during the development cycle it is likely that some ports will break.

<p>
In addition to having all the pieces work together, there is just the
matter of time and resources required to compile some applications from
source.
A common example is <a href="http://www.cvsup.org/">CVSup</a>, a tool
commonly used to <a href="../../zh/cvsup.html">track the OpenBSD source tree</a>.
To install CVSup on a moderately fast system with a good Internet
connection may take only about ten seconds -- the time required
to download and unpack a single 779kB package file.
In contrast, building CVSup on the same machine from source is a huge
task, requiring many tools and bootstrapping a compiler, taking almost
half an hour on the same machine.
Other applications, such as <a href="http://www.mozilla.org">Mozilla</a>
or <a href="http://www.kde.org">KDE</a> may take hours and huge amounts
of disk space and RAM/swap to build.
Why go through this much time and effort, when the programs are already
compiled and sitting on your <a href="../../zh/orders.html">CD-ROM</a> or
<a href="../../zh/ftp.html">FTP mirror</a>, waiting to be used?

<p>
Of course, there are a few good reasons to use ports over packages
in some cases:

<ul>
<li>Distribution rules prohibit OpenBSD from distributing a package.
<li>You wish to modify or debug the application or study its source code.
<li>You need a flavor of a port that is not built by the OpenBSD ports
team.
<li>You wish to alter the directory layout (i.e. modifying <tt>PREFIX</tt>
or <tt>SYSCONFDIR</tt>).
</ul>

However, for most people and most applications, using packages is a much
easier, and definitely the recommended way of adding applications to an
OpenBSD system.


<a name="Knobs"></a>
<h3>15.4.7 - 我该怎么调谐这些 ports 以获得最大性能?</h3>

OpenBSD is about stability and security.
Just like the GENERIC kernel is the default and the only supported kernel,
the ports team makes sure the ports work and are stable.
If you want to switch on all kinds of compiler options, you are on your own.
Please do not ask questions on the mailing lists such as why it does not
work, when you tried to switch on a few hidden knobs to make it work faster.
In general, all this tweaking is not necessary for more than 99% of users,
and it is very likely to be a complete waste of time, for you, the user, as
well as for the developers who read about your "problems" when in reality
there are none.


<a name="Wait"></a>
<h3>15.4.8 几周前，我递交了新的或升级的 ports。为什么它没有被提交?</h3>

The ports team has very limited resources and no committer was able
to look at your port/update in time. As frustrating as it may be, just
ignore this fact. Take care of your port, send updates and eventually
someone might take care of it. It has happened before that people
suddenly have some free time to spend on committing ports or their
interests shift to new areas and suddenly your old submission becomes
interesting, if it is remembered.


<a name="Problems"></a>
<h2>15.5 - 报告问题</h2>

If you have trouble with an existing port, please send e-mail to the
port maintainer.
To see who is the maintainer of the port, type, for example:

<blockquote><pre>
$ cd /usr/ports/archivers/unzip
$ make show=MAINTAINER
</pre></blockquote>

<p>
Alternatively, if there is no maintainer, or you can't reach
him/her, send e-mail to the OpenBSD ports mailing list,
<a href="mailto:ports@openbsd.org">ports@openbsd.org</a>.
Please do NOT use the misc@openbsd.org mailing list for questions
about ports.
<p>
In any case please provide:
<ul>
<li>Your OpenBSD version including any patches you may have applied.
The kernel version is given by: <tt>sysctl -n kern.version</tt>
<li>The version of your ports tree: if the file <tt>/usr/ports/CVS/Tag</tt>
exists, provide its contents.
If this file is absent, you are using the -current ports tree.
<li>A complete description of the problem.
Don't be afraid to provide details.
Mention all the steps you followed before the problem occurred.
Is the problem reproducible?
The more information you provide, the more likely you will get help.
</ul>
For ports which do not build correctly, a complete build transcript is
almost always required.
You can use the portslogger script, found in
<tt>/usr/ports/infrastructure/build</tt>, for this.
A sample run of portslogger might be:

<blockquote><pre>
$ mkdir ~/portslogs
$ cd /usr/ports/archivers/unzip
$ make clean install 2&gt;&amp;1 | /usr/ports/infrastructure/build/portslogger \
           ~/portslogs
</pre></blockquote>

After this, you should have a logfile of the build in your ~/portslogs
directory that you can send to the port maintainer.
Also, make sure you are not using any special options in your build,
for example in <tt>/etc/mk.conf</tt>.

<p>
Alternatively, you can
<ul>
<li>Use
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=script&amp;sektion=1">script(1)</a>
to create a complete build transcript.
Do not remove the configure information.
<li>Attach the output of
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=pkg_info&amp;sektion=1&amp;manpath=OpenBSD+4.3">pkg_info(1)</a>
if it seems even remotely relevant.
<li><a href="http://www.openbsd.org/cgi-bin/man.cgi?query=gcc&amp;sektion=1">gcc(1)</a>
internal compiler errors ask you to report the bug to the gcc
mailinglist.
It does save time if you follow their direction, and provide at least
the various files produced by <tt>gcc -save-temps</tt>.
</ul>


<a name="Helping"></a>
<h2>15.6 - 帮助我们</h2>

There are many ways you can help.
They are listed below, by increasing order of difficulty.

<ul>
<li><a href="#Problems">Report problems</a> as you experience them.
<li>You can systematically test ports and report breakages, or suggest
improvements.
Just have a look at the <a href="../../porttest.html">Port Testing Guide</a>.
<li>Test the updates to ports which are posted to the ports mailing list.
<li>Send updates or patches to a port's maintainer, or to the ports
mailing list if the port has no maintainer.
Generally this is highly appreciated, unless your patches will cause
developers to waste time rather than save time.
<li>Create new ports.
If you are really eager and want to know everything about porting
applications to OpenBSD, a good starting point is
<a href="../../porting.html">Building an OpenBSD Port</a>.
</ul>

<b>Note:</b> For all creation of new ports and subsequent testing, or
for testing port updates, you <b>must run a -current system!</b>
In general, this is not a desirable environment because of its
continuously evolving nature, so proceed only if you are sure about
committing yourself to following -current.

<p>
<font color= "#0000e0">
<a href= "index.html">[FAQ 索引]</a>
<a href= "../faq14.html">[到 14 - 配置磁盘]</a>
</font>

<p>
<hr>
<a href= "index.html"><img height= "24" width= "24" src= "../../images/back.gif" border= "0" alt="[back]"></a>
<a href="mailto:www@openbsd.org">www@openbsd.org</a>
<br>
<small>$OpenBSD: faq15.html,v 1.51 2008/07/04 10:54:24 espie Exp $</small>

</body>
</html>
<!--
Originally [OpenBSD: faq15.html,v 1.51]<br>
$Translation: faq15.html,v 1.4 2008/07/15 05:35:56 dongsheng Exp $<br>
-->
